<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Permission
 * @mixin \Eloquent
 */
class Permission extends Model
{
    protected $fillable = [
        'name',
        'description',
    ];

    public function roles()
    {
        return $this->belongsToMany(Role::class);
    }

    public static function isRepetition($name, $id = null)
    {
        $result = self::where('name', $name);
        if($id) {
            $result = $result->where('id', '!=', $id);
        }
        return $result->first() ? true : false;
    }
}
